﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace Controllers
{
    public class DocNoController : BaseController
    {
        //分页查询
        public ActionResult Find(int start, int limit)
        {
            IQueryable<DocNo> list = from r in ctx.DocNos orderby r.OrderNo descending select r;
            CJson CJson = new CJson();
            string json = CJson.ToJsonString("totalCount:" + list.Count() + ",data", list.Skip(start).Take(limit).ToList());
            return Content(json);
        }

        public ActionResult DeleteDoc(int id)
        {
            var rdto = new ResultMessages();
            rdto.Message = "";
            DocNo list = ctx.DocNos.Single(q => q.Id == id);
            try
            {
                ctx.DocNos.DeleteOnSubmit(list);
                ctx.SubmitChanges();
                rdto.Message = "删除成功";
                rdto.Result = true;
            }
            catch (Exception ex)
            {
                rdto.Message = "删除失败";
                rdto.Result = false;
            }
            return Json(rdto);
        }
    }
}